package cn.edu.ctbu.jpatest.controller;

import cn.edu.ctbu.jpatest.service.TeacherService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author xiaopeng
 * @version 1.0
 */
@Controller
@RequestMapping("/teacher")
@RequiredArgsConstructor
public class TeacherController {
    private final TeacherService teacherService;

    /**
     * 使用thymeleaf的模版引擎完成数据显示
     * 返回model模型
     * @param model
     * @return 返回html静态界面路径，模版teacher/list.html
     */
    @GetMapping("/list")
    public String getList(Model model){
        //将数据放入model模型中
        model.addAttribute("teachers",teacherService.getAll());
        return "teacher/list"; // 返回对应的模版teacher/list.html
    }
}
